package com.winchain.chainbill.bill.biz.send.cmd;

import com.shell.bee.base.utils.StringUtil;
import com.shell.bee.invoince.service.InvBasService;
import com.shell.framework.command.CommandContext;
import com.shell.framework.command.ICommand;
import com.winchain.chainbill.bill.base.dao.CbAttDao;
import com.winchain.chainbill.bill.base.po.CbAtt;
import com.winchain.chainbill.bill.base.po.CbRcv;
import com.winchain.chainbill.bill.base.po.CbRec;
import com.winchain.chainbill.bill.base.po.CbSnd;
import com.winchain.chainbill.bill.biz.Bill;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class BillSndInvoinceRejectICmd<T> implements ICommand<Bill<T>> {
	@Autowired
	private CbAttDao cbAttDao;
	@Autowired
	private InvBasService invBasService;

	public boolean execute(CommandContext<Bill<T>> context) throws Exception {
		CbRec record = ((Bill) context.getSource()).getRec();
		T source = (T) ((Bill) context.getSource()).getSource();
		String sndId = "";
		if ((source instanceof CbSnd)) {
			sndId = ((CbSnd) source).getSndId();
		} else if ((source instanceof CbRcv)) {
			sndId = ((CbRcv) source).getTxId();
		}
		if (!StringUtil.emptyAndNull(sndId)) {
			List<CbAtt> cbAtts = this.cbAttDao.selectDelCbAtt(sndId, record.getBillId(), "6", null);
			for (CbAtt att : cbAtts) {
				this.invBasService.updateInvBlc(att.getAttId(), "2");
			}
		}
		return false;
	}
}
